package com.sclg.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.User;

import com.sclg.dao.IUserDao;
import com.sclg.dao.lmpl.IUserDaolmpl;
import com.sclg.mybatis.service.mybatisfirstblood;
import com.sclg.pojo.IUser;

@WebServlet("/login")
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private IUserDao dao = new IUserDaolmpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		mybatisfirstblood first=new mybatisfirstblood();
		try
		{
		first.findUserByNameTest();
		}
		catch(Exception e)
		{
			 // e.printStackTrace();
			  String x=e.toString();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		mybatisfirstblood first=new mybatisfirstblood();
		first.findUserByNameTest();
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String name = request.getParameter("username");
		String pwd = request.getParameter("password");
		IUser user = dao.Login(name, pwd);
		System.out.println(user);
		System.out.println(name);
		System.out.println(pwd);
		if (user != null) {
			HttpSession session = request.getSession();
			session.setAttribute("user", user);
			response.sendRedirect("jsp/bootstrap.jsp");
		}
		else {

			System.out.println("222222222222222");	
		}
	}

}
